package com.oim.ui.fx.classics.setting;

import com.oim.core.business.constant.Setting;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;

import java.util.function.Consumer;


/**
 * @date 2017-12-08 20:34:10
 */
public class ShortKeySettingPane extends VBox {

    protected ChoiceBox<String> choiceBox = new ChoiceBox();

    public ShortKeySettingPane() {
        initComponent();
        initEvent();
    }

    private void initComponent() {
        Label label = new Label("消息发送");
        String enterDesc = Setting.ENTER;
        choiceBox.getItems().addAll(enterDesc, Setting.CONTROL_ENTER);
        choiceBox.getSelectionModel().select(Setting.shortKey == 0 ? Setting.ENTER : Setting.CONTROL_ENTER);
        this.getChildren().addAll(label, choiceBox);

    }

    private void initEvent() {

    }

    public void setConsumer(Consumer<String> consumer) {
        choiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
            if (Setting.CONTROL_ENTER.equals(newValue)) {
                Setting.shortKey = 1;
                consumer.accept(Setting.CONTROL_ENTER);
            } else {
                Setting.shortKey = 0;
                consumer.accept(Setting.ENTER);
            }
        });
    }

}
